/*
 * main.cpp

 *
 *  Created on: Nov 16, 2012
 *      Author: monitz
 */

#include "../include/main.h"

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <typeinfo>
#include <vector>
#include <time.h>
#include "../include/Course.h"
#include "../include/Student.h"
#include "../include/utils.h"

using namespace std;

int main (int argc, char* argv[]){

	remove("random.log");
	utils parser;
	stringstream sstrm;
	bool malag=false;
	if(argc >1)
	{
		string str = "MALAG=no";
		for(int i=1;i<argc;i++)
		{
		if(str.compare(argv[i])==0)
			malag=true;
		}
	}

	vector<int> amounts = parser.parseCurric();
	vector< vector <Course*> > courselist = parser.parseCourses(malag);
	vector<Student*> studlist = parser.parseStudents(amounts.at(1),amounts.at(2),malag);
	srand(time(0));
	cout << "parsed " << studlist.size() << " students" << endl << "parsed " << courselist.at(0).size() << "/" << courselist.at(1).size() << " courses" << endl;

	//University circle

	while(Course::cur_sem<=amounts.at(0))
	{

		sstrm << "semester " << Course::cur_sem << " out of " << amounts.at(0) << endl;
		parser.log(sstrm);
		sstrm.str("");

		for(unsigned int i=0;i<courselist.at(Course::cur_sem%2).size();i++)
		{
			for(unsigned int j=0; j<studlist.size();j++)
			{
				courselist.at(Course::cur_sem%2).at(i)->reg(*studlist.at(j));

			}
			courselist.at(Course::cur_sem%2).at(i)->printStudents();
		}
		for(unsigned int j=0; j<studlist.size();j++)
					{
						studlist.at(j)->resetSem();

					}

		for(unsigned int i=0;i<courselist.at(Course::cur_sem%2).size();i++)
				{
			courselist.at(Course::cur_sem%2).at(i)->teach();
				}

		for(unsigned int j=0; j<studlist.size();j++)
					{
						studlist.at(j)->grad();
					}
		Course::cur_sem++;
	}

	parser.showUniGraduation(studlist);

	for(unsigned int i=0;i<courselist.at(0).size();i++)
		delete courselist.at(0).at(i);
	for(unsigned int i=0;i<courselist.at(1).size();i++)
			delete courselist.at(1).at(i);
	for(unsigned int i=0;i<studlist.size();i++)
			delete studlist.at(i);

	return 0;
}
